<script setup>
import {ref,onMounted} from 'vue'
import{queryPageApi} from '@/api/log' 
import { ElMessage} from 'element-plus'

// 日志列表
const logList = ref([])

// 分页
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(10)
const background = ref(true)

// 分页查询
const getLogList = async () => {
  const res = await queryPageApi(currentPage.value,pageSize.value)
  if(res.code){
    logList.value = res.data.rows
    total.value = res.data.total
  }
  else{
    ElMessage.error('查询日志失败')
  }
}
// 每页展示记录数变化
const handleSizeChange = (val) => {
  getLogList()
}
// 页码变化时触发
const handleCurrentChange = (val) => {
  getLogList()
}
// 钩子函数
onMounted(() => {
  getLogList()
})
</script>

<template>
  <h1>日志管理</h1> 
  <!-- 日志列表 -->
  <div class="container">
    <el-table :data="logList" border style="width: 100%" >
    <el-table-column prop="operateEmpName" label="操作人" width="90" align = "center" />
    <el-table-column prop="operateTime" label="操作时间" width="160" align = "center" />
    <el-table-column prop="className" label="类名" width="320" align = "center" />
    <el-table-column prop="methodName" label="方法名" width="130" align = "center" />
    <el-table-column prop="costTime" label="操作耗时(ms)" width="90" align = "center" />
    <el-table-column prop="methodParams" label="请求参数" width="200" show-overflow-tooltip 
    align = "center"  />
    <el-table-column prop="returnValue" label="返回值" align = "center" />
    </el-table>
  </div>

<!-- 分页条 -->
  <div class="container">
    <el-pagination
    v-model:current-page="currentPage"
    v-model:page-size="pageSize"
    :page-sizes="[5,10, 20, 30, 40, 50,75,100]"
    :background="background"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
  </div>
</template>

<style scoped>
.container {
  margin: 10px 0px;
}

/* 调整表格字体大小 */
.el-table {
  font-size: 12px;
}

/* 调整分页字体大小 */
.el-pagination {
  font-size: 12px;
}
</style>